﻿using System;
using System.Collections.Generic;

#if(!XBOX360)
using System.Diagnostics;
#endif

namespace State_Machine
{
    /// <summary>
    /// State structure
    /// </summary>
    class State
    {
        // The list of the transitions possible for this state
        Dictionary<string, State> transitions = new Dictionary<string, State>();

        public State()
        {

        }

        /// <summary>
        /// Add a transition
        /// </summary>
        /// <param name="transitionName">the name of the transition</param>
        /// <param name="nextState">the next state</param>
        public void addTransition(string transitionName, State nextState)
        {
            transitions.Add(transitionName, nextState);
        }

        /// <summary>
        /// Get if this transition is possible
        /// </summary>
        /// <param name="transitionName">the name of the transition</param>
        /// <returns></returns>
        public bool isAble(string transitionName)
        {
            return transitions.ContainsKey(transitionName);
        }

        /// <summary>
        /// Get the next state (after applying the transition)
        /// </summary>
        /// <param name="transitionName">the name of the transition</param>
        /// <returns></returns>
        public State getState(string transitionName)
        {
#if(!XBOX360)
            Trace.Assert(transitions.ContainsKey(transitionName), "This transition doesn't exist");
#endif

            return transitions[transitionName];
        }

        /// <summary>
        /// Get if we are at the final state (no more transition possible)
        /// </summary>
        /// <returns></returns>
        public bool isFinal()
        {
            if (transitions.Count == 0)
                return true;
            return false;
        }
    }
}
